unit mostracategorie_frm;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  DBGrids, ExtCtrls, DbCtrls, db, ZDataset, ComCtrls, StdCtrls, datamodule_frm, categorie_frm;

type

  { TMostracategorie }

  TMostracategorie = class(TForm)
    btmodifica: TButton;
    datasource1: TDatasource;
    grigliacampi: TDBGrid;
    Image1: TImage;
    Splitter1: TSplitter;
    ToolBar1: TToolBar;
    zq_categoria: TZReadOnlyQuery;
    procedure btmodificaClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
    idcategoria_sel:integer;
  end; 

var
  Mostracategorie: TMostracategorie;

implementation

{ TMostracategorie }



procedure TMostracategorie.FormShow(Sender: TObject);
var stream:TMemoryStream;
begin
  //carico i dati della categoria
  stream:=TMemoryStream.Create;
  //mostro nei campi l'azienda selezionata
  with zq_categoria do
     begin
        Close;
        sql.Clear;
        sql.Add('SELECT immagine FROM CATEGORIE WHERE IDCATEGORIA=:ID');
        ParamByName('ID').AsInteger:=idcategoria_sel;
        ExecSQL;
        Open;
        if not FieldByName('immagine').IsNull then
          begin
               TBlobField(FieldByName('immagine')).SaveTostream(stream);
               stream.Position:=0;
               Image1.Picture.Jpeg.LoadFromStream(stream);
          end
        else
            Image1.Picture.Clear;
        stream.free;
        Close;
     end;
  with zq_categoria do
       begin
              //seleziono tutti i campi che fanno capo a questo id
              close;
              sql.clear;
              sql.add('SELECT IDCATEGORIA_EXT,gruppo,NOME_CAMPO,VALORE FROM CATEGORIE_EXT '+
                      'WHERE IDCATEGORIA=:IDCAT '+
                      'ORDER BY gruppo,NOME_CAMPO');
              ParamByName('IDCAT').AsInteger:=idcategoria_sel;
              ExecSQL;
              open;
         end;
         With grigliacampi do
              begin
                   Columns[0].Visible:=false;
                   Columns[1].Width:=50;
                   Columns[2].Width:=200;
                   Columns[3].Width:=200;
                   Columns[1].Title.Caption:=' ';
                   Columns[2].Title.Caption:='Campo';
                   Columns[3].Title.Caption:='Valore';

              end;

end;

procedure TMostracategorie.btmodificaClick(Sender: TObject);
begin
  categorie:=tcategorie.create(self);
  categorie.idcategoria_sel:=idcategoria_sel;
  Categorie.Show;
end;



initialization
  {$I mostracategorie_frm.lrs}

end.

